package logic

import (
	"context"
	"week1/textrpc/models"
	"week1/textrpc/service"

	"week1/textrpc/internal/svc"
	"week1/textrpc/textrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BarrageLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBarrageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BarrageLogic {
	return &BarrageLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Barrage todo 文章评论
func (l *BarrageLogic) Barrage(in *textrpc.BarrageReq) (*textrpc.BarrageRes, error) {
	// todo: add your logic here and delete this line
	err := service.CreateBarrage(&models.TextBarrage{
		TextId:  in.TextId,
		Userid:  in.Userid,
		Comment: in.Comment,
		Pid:     in.BarrageId,
	})
	if err != nil {
		return &textrpc.BarrageRes{}, err
	}
	return &textrpc.BarrageRes{}, nil
}
